home *** CD-ROM | disk | FTP | other *** search
/ Aminet 1 (Walnut Creek) / Aminet - June 1993 [Walnut Creek].iso / aminet / util / gnu / diff_2_1.lha / diff-2.1 / amiga-diff.diffs < prev    next >
Text File  |  1993-02-04  |  28KB  |  1,138 lines

  1. diff -cr ram:diff-2.1/alloca.c dh1:diff-2.1/alloca.c
  2. *** ram:diff-2.1/alloca.c    Tue Dec 01 19:25:52 1992
  3. --- dh1:diff-2.1/alloca.c    Wed Feb 03 20:32:25 1993
  4. ***************
  5. *** 71,76 ****
  6. --- 71,80 ----
  7.       STACK_DIRECTION = 0 => direction of growth unknown
  8.   */
  9.   
  10. + #ifdef AMIGA
  11. + #define    STACK_DIRECTION    -1
  12. + #endif /* AMIGA */
  13.   #ifndef STACK_DIRECTION
  14.   #define    STACK_DIRECTION    0        /* direction unknown */
  15.   #endif
  16. diff -cr ram:diff-2.1/cmp.c dh1:diff-2.1/cmp.c
  17. *** ram:diff-2.1/cmp.c    Wed Jul 08 21:58:06 1992
  18. --- dh1:diff-2.1/cmp.c    Wed Feb 03 20:00:05 1993
  19. ***************
  20. *** 28,33 ****
  21. --- 28,36 ----
  22.   int cmp ();
  23.   void printc ();
  24.   void error ();
  25. + #ifdef AMIGA
  26. + void fake_stat_result ();
  27. + #endif /* AMIGA */
  28.   
  29.   /* Name under which this program was invoked.  */
  30.   char *program_name;
  31. ***************
  32. *** 166,175 ****
  33. --- 169,191 ----
  34.       usage ("at least one filename should be specified");
  35.       }
  36.   
  37. + #ifndef AMIGA
  38.     if (fstat (file1_desc, &stat_buf1) < 0)
  39.       error (2, errno, "%s", file1);
  40.     if (fstat (file2_desc, &stat_buf2) < 0)
  41.       error (2, errno, "%s", file2);
  42. + #else /* AMIGA */
  43. +   if (file1_desc != 0)
  44. +     if (fstat (file1_desc, &stat_buf1) < 0)
  45. +       error (2, errno, "%s", file1);
  46. +   else
  47. +     fake_stat_result (&stat_buf1);
  48. +   if (file2_desc != 0)
  49. +     if (fstat (file2_desc, &stat_buf2) < 0)
  50. +       error (2, errno, "%s", file2);
  51. +   else
  52. +     fake_stat_result (&stat_buf2);
  53. + #endif /* AMIGA */
  54.   
  55.     /* If both the input descriptors are associated with plain files,
  56.        we can make the job simpler in some cases.  */
  57. ***************
  58. *** 185,190 ****
  59. --- 201,207 ----
  60.   
  61.         /* If output is redirected to "/dev/null", we may assume `-s'.  */
  62.   
  63. + #ifndef AMIGA
  64.         if (comparison_type != type_status)
  65.       {
  66.         struct stat sb;
  67. ***************
  68. *** 200,205 ****
  69. --- 217,223 ----
  70.           comparison_type = type_status;
  71.           }
  72.       }
  73. + #endif /* AMIGA */
  74.   
  75.         /* If only a return code is needed, conclude that
  76.        the files differ if they have different sizes.  */
  77. ***************
  78. *** 510,512 ****
  79. --- 528,548 ----
  80.     while (--width > 0)
  81.       putc (' ', fs);
  82.   }
  83. + #ifdef AMIGA
  84. + void fake_stat_result (sbuf)
  85. +      struct stat *sbuf;
  86. + {
  87. +   time_t cur_time;
  88. +   time (&cur_time);
  89. +   sbuf->st_dev = 0;
  90. +   sbuf->st_ino = 0;
  91. +   sbuf->st_mode = S_IREAD;
  92. +   sbuf->st_nlink = 1;
  93. +   sbuf->st_uid = 0;
  94. +   sbuf->st_gid = 0;
  95. +   sbuf->st_size = 0;
  96. +   sbuf->st_ctime = sbuf->st_atime = sbuf->st_mtime = cur_time;
  97. + }
  98. + #endif /* AMIGA */
  99. diff -cr ram:diff-2.1/diff.c dh1:diff-2.1/diff.c
  100. *** ram:diff-2.1/diff.c    Wed Nov 18 17:17:00 1992
  101. --- dh1:diff-2.1/diff.c    Thu Feb 04 11:38:14 1993
  102. ***************
  103. *** 41,46 ****
  104. --- 41,49 ----
  105.   static void add_regexp();
  106.   static void specify_style ();
  107.   static void usage ();
  108. + #ifdef AMIGA
  109. + static int fake_stat_result ();
  110. + #endif /* AMIGA */
  111.   
  112.   /* Nonzero for -r: if comparing two directories,
  113.      compare their common subdirectories recursively.  */
  114. ***************
  115. *** 720,727 ****
  116. --- 723,751 ----
  117.     if (name1 == 0)
  118.       name1 = name0;
  119.   
  120. + #ifndef AMIGA
  121.     inf[0].name = dir0 == 0 ? name0 : concat (dir0, "/", name0);
  122.     inf[1].name = dir1 == 0 ? name1 : concat (dir1, "/", name1);
  123. + #else /* AMIGA */
  124. +   {
  125. +     int len = strlen (dir0);
  126. +     if (dir0 == 0 || len == 0)
  127. +       inf[0].name = name0;
  128. +     else if (dir0[len-1] == ':')
  129. +       inf[0].name = concat (dir0, "", name0);
  130. +     else
  131. +       inf[0].name = concat (dir0, "/", name0);
  132. +   }
  133. +   {
  134. +     int len = strlen (dir1);
  135. +     if (dir1 == 0 || len == 0)
  136. +       inf[1].name = name1;
  137. +     else if (dir1[len-1] == ':')
  138. +       inf[1].name = concat (dir1, "", name1);
  139. +     else
  140. +       inf[1].name = concat (dir1, "/", name1);
  141. +   }
  142. + #endif /* AMIGA */
  143.   
  144.     /* Stat the files.  Record whether they are directories.  */
  145.   
  146. ***************
  147. *** 738,744 ****
  148. --- 762,772 ----
  149.           {
  150.             inf[i].desc = 0;
  151.             inf[i].name = "Standard Input";
  152. + #ifndef AMIGA
  153.             stat_result = fstat (0, &inf[i].stat);
  154. + #else /* AMIGA */
  155. +           stat_result = fake_stat_result (&inf[i].stat);
  156. + #endif /* AMIGA */
  157.           }
  158.         else
  159.           stat_result = stat (inf[i].name, &inf[i].stat);
  160. ***************
  161. *** 763,773 ****
  162. --- 791,819 ----
  163.         /* If one is a directory, and it was specified in the command line,
  164.        use the file in that dir with the other file's basename.  */
  165.   
  166. + #ifndef AMIGA
  167.         int fnm_arg = inf[0].dir_p;
  168.         int dir_arg = 1 - fnm_arg;
  169.         char *p = rindex (inf[fnm_arg].name, '/');
  170.         char *filename = inf[dir_arg].name
  171.       = concat (inf[dir_arg].name,  "/", (p ? p+1 : inf[fnm_arg].name));
  172. + #else /* AMIGA */
  173. +       int fnm_arg, dir_arg;
  174. +       char *p1, *p2, *p;
  175. +       char *filename;
  176. +       fnm_arg = inf[0].dir_p;
  177. +       dir_arg = 1 - fnm_arg;
  178. +       p1 = rindex (inf[fnm_arg].name, '/');
  179. +       p2 = rindex (inf[fnm_arg].name, ':');
  180. +       p = max (p1, p2);
  181. +       if (*(inf[dir_arg].name + strlen (inf[dir_arg].name) - 1) == ':')
  182. +         filename = inf[dir_arg].name
  183. +           = concat (inf[dir_arg].name, "", (p ? p+1 : inf[fnm_arg].name));
  184. +       else
  185. +         filename = inf[dir_arg].name
  186. +           = concat (inf[dir_arg].name, "/", (p ? p+1 : inf[fnm_arg].name));
  187. + #endif /* !AMIGA */
  188.   
  189.         if (inf[fnm_arg].desc == 0)
  190.       fatal ("can't compare - to a directory");
  191. ***************
  192. *** 911,920 ****
  193. --- 957,992 ----
  194.     else
  195.       fflush (stdout);
  196.   
  197. + #ifndef AMIGA
  198.     if (dir0 != 0)
  199.       free (inf[0].name);
  200.     if (dir1 != 0)
  201.       free (inf[1].name);
  202. + #else /* AMIGA */
  203. +   if (dir0 != 0 && strlen(dir0) != 0)
  204. +     free (inf[0].name);
  205. +   if (dir1 != 0 && strlen(dir1) != 0)
  206. +     free (inf[1].name);
  207. + #endif /* !AMIGA */
  208.   
  209.     return val;
  210.   }
  211. + #ifdef AMIGA
  212. + static int fake_stat_result (sbuf)
  213. +      struct stat *sbuf;
  214. + {
  215. +   time_t cur_time;
  216. +   time (&cur_time);
  217. +   sbuf->st_dev = 0;
  218. +   sbuf->st_ino = 0;
  219. +   sbuf->st_mode = S_IREAD;
  220. +   sbuf->st_nlink = 1;
  221. +   sbuf->st_uid = 0;
  222. +   sbuf->st_gid = 0;
  223. +   sbuf->st_size = 0;
  224. +   sbuf->st_ctime = sbuf->st_atime = sbuf->st_mtime = cur_time;
  225. +   return 0;
  226. + }
  227. + #endif /* AMIGA */
  228. diff -cr ram:diff-2.1/diff3.c dh1:diff-2.1/diff3.c
  229. *** ram:diff-2.1/diff3.c    Thu Nov 12 17:02:18 1992
  230. --- dh1:diff-2.1/diff3.c    Thu Feb 04 11:47:01 1993
  231. ***************
  232. *** 28,33 ****
  233. --- 28,43 ----
  234.   #include "getopt.h"
  235.   #include "system.h"
  236.   
  237. + #ifdef AMIGA
  238. + #include <signal.h>
  239. + #include <exec/types.h>
  240. + #include <dos/dostags.h>
  241. + #include <proto/dos.h>
  242. + #include <proto/exec.h>
  243. + extern struct DosLibrary *DOSBase;
  244. + #endif /* AMIGA */
  245.   /*
  246.    * Internal data structures and macros for the diff3 program; includes
  247.    * data structures for both diff3 diffs and normal diffs.
  248. ***************
  249. *** 197,203 ****
  250. --- 207,217 ----
  251.   
  252.   static struct diff3_block *reverse_diff3_blocklist ();
  253.   
  254. + #ifndef AMIGA
  255.   static VOID *xmalloc ();
  256. + #else /* AMIGA */
  257. + VOID *xmalloc ();
  258. + #endif /* !AMIGA */
  259.   static VOID *xrealloc ();
  260.   
  261.   static char diff_program[] = DIFF_PROGRAM;
  262. ***************
  263. *** 240,245 ****
  264. --- 254,266 ----
  265.     char **file;
  266.     struct stat statb;
  267.   
  268. + #ifdef AMIGA
  269. +   if (DOSBase->dl_lib.lib_Version < 37) {
  270. +     fputs ("Need Amiga OS 2.0 (V.37) to execute.\n", stderr);
  271. +     exit (20);
  272. +   }
  273. + #endif /* AMIGA */
  274.     incompat = 0;
  275.   
  276.     argv0 = argv[0];
  277. ***************
  278. *** 1089,1094 ****
  279. --- 1110,1117 ----
  280.        char *filea, *fileb;
  281.        char **output_placement;
  282.   {
  283. + #ifndef AMIGA
  284.     char *argv[6];
  285.     char **ap;
  286.     int fds[2];
  287. ***************
  288. *** 1132,1137 ****
  289. --- 1155,1230 ----
  290.       perror_with_exit ("fork failed");
  291.   
  292.     close (fds[1]);        /* Prevent erroneous lack of EOF */
  293. + #else /* AMIGA */
  294. +   static char diff_command_line[200];
  295. +   int fds[2];
  296. +   char *diff_result;
  297. +   int current_chunk_size;
  298. +   int bytes;
  299. +   int total;
  300. +   void (*oldsigint)();
  301. +   static long num_invocations = 0;
  302. +   char pipe_name[20];
  303. +   struct Task *Task;
  304. +   struct TagItem STags[5];
  305. +   BPTR StdOutDiff;
  306. +   /* The user should not be able to break the program while the child
  307. +      process is being executed, otherwise the child process will still
  308. +      be writing to the pipe-device until it deadlocks because there is
  309. +      no reader on the other side of the pipe. So prohibit breaking the
  310. +      program until the pipe is closed. */
  311. +   oldsigint = signal (SIGINT, SIG_IGN);
  312. +   /* Construct command line. Enclose filenames in double quotes in
  313. +      case the user specifies files with spaces in their names. */
  314. +   strcpy (diff_command_line, diff_program);
  315. +   if (always_text)
  316. +     strcat (diff_command_line, " -a");
  317. +   strcat (diff_command_line, " --");
  318. +   strcat (diff_command_line, " \"");
  319. +   strcat (diff_command_line, filea);
  320. +   strcat (diff_command_line, "\" \"");
  321. +   strcat (diff_command_line, fileb);
  322. +   strcat (diff_command_line, "\"");
  323. +   /* Construct filename for the pipe to be used */
  324. +   Task = FindTask (NULL);
  325. +   num_invocations++;
  326. +   sprintf (pipe_name, "PIPE:%08lX_%ld", Task, num_invocations);
  327. +   /* Open pipe for child process */
  328. +   StdOutDiff = Open (pipe_name, MODE_NEWFILE);
  329. +   if (!StdOutDiff)
  330. +     perror_with_exit ("pipe failed");
  331. +   /* Child process runs asynchronously with pipe as stdout */
  332. +   STags[0].ti_Tag = SYS_Input;
  333. +   STags[0].ti_Data = NULL;
  334. +   STags[1].ti_Tag = SYS_Output;
  335. +   STags[1].ti_Data = StdOutDiff;
  336. +   STags[2].ti_Tag = SYS_Asynch;
  337. +   STags[2].ti_Data = TRUE;
  338. +   STags[3].ti_Tag = SYS_UserShell;
  339. +   STags[3].ti_Data = TRUE;
  340. +   STags[4].ti_Tag = TAG_DONE;
  341. +   /* Start child process */
  342. +   if ((System (diff_command_line, STags)) != 0) {
  343. +     Close (StdOutDiff);
  344. +     perror_with_exit ("diff: not found");
  345. +   }
  346. +   /* Open pipe for this side of the communication */
  347. +   fds[0] = open (pipe_name, O_RDONLY);
  348. +   if (fds[0] < 0) {
  349. +     Close (StdOutDiff);
  350. +     perror_with_exit ("pipe failed");
  351. +   }
  352. + #endif /* !AMIGA */
  353.     current_chunk_size = DIFF_CHUNK_SIZE;
  354.     diff_result = (char *) xmalloc (current_chunk_size);
  355.     total = 0;
  356. ***************
  357. *** 1149,1154 ****
  358. --- 1242,1248 ----
  359.   
  360.     *output_placement = diff_result;
  361.   
  362. + #ifndef AMIGA
  363.     do
  364.       if ((w = wait (&wstatus)) == -1)
  365.         perror_with_exit ("wait failed");
  366. ***************
  367. *** 1156,1161 ****
  368. --- 1250,1261 ----
  369.   
  370.     if (! (WIFEXITED (wstatus) && WEXITSTATUS (wstatus) < 2))
  371.       fatal ("subsidiary diff failed");
  372. + #else /* AMIGA */
  373. +   /* Close pipe */
  374. +   close (fds[0]);
  375. +   /* Re-install break-handler */
  376. +   signal (SIGINT, oldsigint);
  377. + #endif /* !AMIGA */
  378.   
  379.     return diff_result + total;
  380.   }
  381. ***************
  382. *** 1638,1644 ****
  383. --- 1738,1748 ----
  384.     return result;
  385.   }
  386.   
  387. + #ifndef AMIGA
  388.   static VOID *
  389. + #else /* AMIGA */
  390. + VOID *
  391. + #endif /* !AMIGA */
  392.   xmalloc (size)
  393.        unsigned size;
  394.   {
  395. diff -cr ram:diff-2.1/dir.c dh1:diff-2.1/dir.c
  396. *** ram:diff-2.1/dir.c    Wed Nov 18 21:40:28 1992
  397. --- dh1:diff-2.1/dir.c    Wed Feb 03 20:26:25 1993
  398. ***************
  399. *** 97,104 ****
  400. --- 97,108 ----
  401.         errno = e;
  402.         return -1;
  403.       }
  404. + #ifndef AMIGA
  405.         if (closedir (reading) != 0)
  406.       return -1;
  407. + #else /* AMIGA */
  408. +       closedir (reading);
  409. + #endif /* !AMIGA */
  410.       }
  411.   
  412.     /* Create the `files' table from the `data' table.  */
  413. diff -cr ram:diff-2.1/fnmatch.c dh1:diff-2.1/fnmatch.c
  414. *** ram:diff-2.1/fnmatch.c    Wed Nov 18 20:24:16 1992
  415. --- dh1:diff-2.1/fnmatch.c    Wed Feb 03 20:28:10 1993
  416. ***************
  417. *** 16,22 ****
  418. --- 16,26 ----
  419.   Cambridge, MA 02139, USA.  */
  420.   
  421.   #include <errno.h>
  422. + #ifndef AMIGA
  423.   #include <fnmatch.h>
  424. + #else /* AMIGA */
  425. + #include "fnmatch.h"
  426. + #endif /* !AMIGA */
  427.   
  428.   #if !defined(__GNU_LIBRARY__) && !defined(STDC_HEADERS)
  429.   extern int errno;
  430. diff -cr ram:diff-2.1/getopt.c dh1:diff-2.1/getopt.c
  431. *** ram:diff-2.1/getopt.c    Mon Jan 18 01:50:26 1993
  432. --- dh1:diff-2.1/getopt.c    Wed Feb 03 20:30:10 1993
  433. ***************
  434. *** 42,50 ****
  435. --- 42,52 ----
  436.   #endif /* alloca.h */
  437.   #endif /* not __GNUC__ */
  438.   
  439. + #ifndef AMIGA
  440.   #if !__STDC__ && !defined(const) && IN_GCC
  441.   #define const
  442.   #endif
  443. + #endif /* !AMIGA */
  444.   
  445.   #include <stdio.h>
  446.   
  447. diff -cr ram:diff-2.1/getopt1.c dh1:diff-2.1/getopt1.c
  448. *** ram:diff-2.1/getopt1.c    Mon Jan 18 01:51:30 1993
  449. --- dh1:diff-2.1/getopt1.c    Wed Feb 03 20:30:42 1993
  450. ***************
  451. *** 21,29 ****
  452. --- 21,31 ----
  453.   
  454.   #include "getopt.h"
  455.   
  456. + #ifndef AMIGA
  457.   #if !__STDC__ && !defined(const) && IN_GCC
  458.   #define const
  459.   #endif
  460. + #endif /* !AMIGA */
  461.   
  462.   #include <stdio.h>
  463.   
  464. diff -cr ram:diff-2.1/sdiff.c dh1:diff-2.1/sdiff.c
  465. *** ram:diff-2.1/sdiff.c    Mon Nov 09 04:59:56 1992
  466. --- dh1:diff-2.1/sdiff.c    Wed Feb 03 22:18:17 1993
  467. ***************
  468. *** 25,30 ****
  469. --- 25,39 ----
  470.   #include <signal.h>
  471.   #include "getopt.h"
  472.   
  473. + #ifdef AMIGA
  474. + #include <exec/types.h>
  475. + #include <dos/dostags.h>
  476. + #include <proto/exec.h>
  477. + #include <proto/dos.h>
  478. + extern struct DosLibrary *DOSBase;
  479. + #endif /* AMIGA */
  480.   #ifndef SEEK_SET
  481.   #define SEEK_SET 0
  482.   #endif
  483. ***************
  484. *** 49,69 ****
  485. --- 58,93 ----
  486.   
  487.   static char *tmpname;
  488.   static int volatile tmpmade;
  489. + #ifndef AMIGA
  490.   static pid_t volatile diffpid;
  491. + #endif /* !AMIGA */
  492.   
  493.   struct line_filter;
  494.   static void diffarg (); /* (char *); */
  495.   static void execdiff (); /* (int, char const *, char const *, char const *); */
  496. + #ifdef AMIGA
  497. + char *xmalloc ();
  498. + static void amiga_exit ();
  499. + static int amiga_break ();
  500. + static void construct_pipe_name ();
  501. + static void construct_command_line ();
  502. + static char command_line[512];
  503. + static FILE *diff_file = NULL;
  504. + static int user_quit = 0;
  505. + #endif /* AMIGA */
  506.   static int edit (); /* (struct line_filter *left, int lenl, struct
  507.                  line_filter *right, int lenr, FILE *outfile); */
  508.   static int interact (); /* (struct line_filter *diff,
  509.                 struct line_filter *left,
  510.                 struct line_filter *right, FILE *outfile); */
  511. + #ifndef AMIGA
  512.   static void trapsigs (); /* (void); */
  513.   /* this lossage until the gnu libc conquers the universe */
  514.   #define TMPNAMSIZE 1024
  515.   #define PVT_tmpdir "/tmp"
  516.   static char *private_tempnam (); /* (const char *, const char *, int, int *); */
  517. + #endif /* !AMIGA */
  518.   static int diraccess ();
  519.   
  520.   /* Options: */
  521. ***************
  522. *** 108,120 ****
  523. --- 132,185 ----
  524.     exit (2);
  525.   }
  526.   
  527. + #ifdef AMIGA
  528. + static void
  529. + amiga_exit ()
  530. + {
  531. +   char *buf;
  532. +   size_t a;
  533. +   if (tmpmade)
  534. +     {
  535. +       remove (tmpname);
  536. +       tmpmade = 0;
  537. +     }
  538. +   if (diff_file)
  539. +     {
  540. +       /* Provide empty pipe! */
  541. +       buf = xmalloc (SDIFF_BUFSIZE);
  542. +       do
  543. +         a = fread (buf, sizeof (char), SDIFF_BUFSIZE, diff_file);
  544. +       while (a == SDIFF_BUFSIZE);
  545. +       fclose (diff_file);
  546. +       diff_file = NULL;
  547. +       free (buf);
  548. +     }
  549. + }
  550. + static int
  551. + amiga_break ()
  552. + {
  553. +   amiga_exit ();
  554. +   return 20;
  555. + }
  556. + #endif /* AMIGA */
  557.   static void
  558.   cleanup ()
  559.   {
  560. + #ifndef AMIGA
  561.     if (0 < diffpid)
  562.       kill (diffpid, SIGPIPE);
  563.     if (tmpmade)
  564.       unlink (tmpname);
  565. + #else /* AMIGA */
  566. +   if (tmpmade)
  567. +     {
  568. +       remove (tmpname);
  569. +       tmpmade = 0;
  570. +     }
  571. + #endif /* !AMIGA */
  572.   }
  573.   
  574.   static void
  575. ***************
  576. *** 230,235 ****
  577. --- 295,301 ----
  578.   }
  579.   #endif
  580.   
  581. + #ifndef AMIGA
  582.   #ifndef HAVE_WAITPID
  583.   /* Emulate waitpid well enough for sdiff, which has at most two children.  */
  584.   static pid_t
  585. ***************
  586. *** 259,264 ****
  587. --- 325,331 ----
  588.     return pid;
  589.   }
  590.   #endif
  591. + #endif /* !AMIGA */
  592.   
  593.   static char const *
  594.   expand_name (name, isdir, other_name)
  595. ***************
  596. *** 273,278 ****
  597. --- 340,346 ----
  598.     else
  599.       {
  600.         /* Yield NAME/BASE, where BASE is OTHER_NAME's basename.  */
  601. + #ifndef AMIGA
  602.         const char
  603.       *p = rindex (other_name, '/'),
  604.       *base = p ? p+1 : other_name;
  605. ***************
  606. *** 282,287 ****
  607. --- 350,381 ----
  608.         r[namelen] = '/';
  609.         bcopy (base, r + namelen + 1, baselen + 1);
  610.         return r;
  611. + #else /* AMIGA */
  612. +       const char *p1, *p2, *base;
  613. +       size_t namelen, baselen;
  614. +       char *r;
  615. +       p1 = rindex (other_name, '/');
  616. +       p2 = rindex (other_name, ':');
  617. +       if (p1 == NULL && p2 == NULL)
  618. +         base = other_name;
  619. +       else
  620. +         base = max (p1 + 1 , p2 + 1);
  621. +       namelen = strlen (name);
  622. +       baselen = strlen (base);
  623. +       r = xmalloc (namelen + baselen + 2);
  624. +       bcopy (name, r, namelen);
  625. +       if (name[namelen-1] != ':')
  626. +         {
  627. +           r[namelen] = '/';
  628. +           bcopy (base, r + namelen + 1, baselen + 1);
  629. +         }
  630. +       else
  631. +         {
  632. +           bcopy (base, r + namelen, baselen + 1);
  633. +         }
  634. +       return r;
  635. + #endif /* AMIGA */
  636.       }
  637.   }
  638.   
  639. ***************
  640. *** 409,414 ****
  641. --- 503,520 ----
  642.     char *editor = getenv ("EDITOR");
  643.     char *differ = getenv ("DIFF");
  644.   
  645. + #ifdef AMIGA
  646. +   if (DOSBase->dl_lib.lib_Version < 37) {
  647. +     fputs ("Need Amiga OS 2.0 (V.37) to execute.\n", stderr);
  648. +     exit (20);
  649. +   }
  650. +   /* Install break and exit traps */
  651. +   if (atexit (&amiga_exit))
  652. +     fatal ("couldn't set exit trap");
  653. +   if (onbreak (&amiga_break))
  654. +     fatal ("couldn't set break trap");
  655. + #endif /* AMIGA */
  656.     prog = argv[0];
  657.     if (editor)
  658.       edbin = editor;
  659. ***************
  660. *** 496,508 ****
  661. --- 602,620 ----
  662.   
  663.     if (! out_file)
  664.       /* easy case: diff does everything for us */
  665. + #ifndef AMIGA
  666.       execdiff (suppress_common_flag, "-y", argv[optind], argv[optind + 1]);
  667. + #else /* AMIGA */
  668. +     execdiff (suppress_common_flag, "-y", argv[optind], argv[optind + 1], FALSE, NULL);
  669. + #endif /* !AMIGA */
  670.     else
  671.       {
  672.         FILE *left, *right, *out, *diffout;
  673.         int diff_fds[2];
  674.         int interact_ok;
  675. + #ifndef AMIGA
  676.         pid_t pid;
  677. + #endif
  678.         struct line_filter lfilt;
  679.         struct line_filter rfilt;
  680.         struct line_filter diff_filt;
  681. ***************
  682. *** 517,522 ****
  683. --- 629,636 ----
  684.         right = ck_fopen (expand_name (argv[optind + 1], rightdir, argv[optind]), "r");
  685.         out = ck_fopen (out_file, "w");
  686.   
  687. + #ifndef AMIGA
  688.         if (pipe (diff_fds))
  689.       perror_fatal ("pipe");
  690.   
  691. ***************
  692. *** 545,562 ****
  693. --- 659,709 ----
  694.         close (diff_fds[1]);
  695.         diffout = ck_fdopen (diff_fds[0], "r");
  696.   
  697. + #else /* AMIGA */
  698. +       {
  699. +         BPTR StdOutDiff;
  700. +         char pipe_name[20];
  701. +         construct_pipe_name (pipe_name);
  702. +         StdOutDiff = Open (pipe_name, MODE_NEWFILE);
  703. +         if (!StdOutDiff)
  704. +           perror_fatal ("pipe");
  705. +         diff_fds[0] = open (pipe_name, O_RDONLY);
  706. +         if (diff_fds[0] == -1)
  707. +           perror_fatal ("pipe");
  708. +         execdiff (0, "--sdiff-merge-assist", argv[optind], argv[optind + 1], TRUE, StdOutDiff);
  709. +       }
  710. +       diffout = ck_fdopen (diff_fds[0], "r");
  711. +       diff_file = diffout;
  712. + #endif /* !AMIGA */
  713.         lf_init (&diff_filt, diffout);
  714.         lf_init (&lfilt, left);
  715.         lf_init (&rfilt, right);
  716.   
  717.         interact_ok = interact (&diff_filt, &lfilt, &rfilt, out);
  718.   
  719. + #ifndef AMIGA
  720.         ck_fclose (diffout);
  721. + #else /* AMIGA */
  722. +       /* If the user signaled quit, let the exit code clean up the
  723. +          pipe and close the file */
  724. +       if (!user_quit)
  725. +         ck_fclose (diffout);
  726. + #endif /* !AMIGA */
  727.         ck_fclose (left);
  728.         ck_fclose (right);
  729.         ck_fclose (out);
  730.   
  731.         {
  732. + #ifndef AMIGA
  733.       int wstatus;
  734.   
  735.       if (waitpid (pid, &wstatus, 0) < 0)
  736. ***************
  737. *** 576,581 ****
  738. --- 723,742 ----
  739.         fatal ("Subsidiary diff failed");
  740.   
  741.       exit (WEXITSTATUS (wstatus));
  742. + #else /* AMIGA */
  743. +     if (tmpmade)
  744. +       {
  745. +         remove (tmpname);
  746. +         tmpmade = 0;
  747. +       }
  748. +     if (! interact_ok)
  749. +       exit (2);
  750. +         diff_file = NULL;
  751. +         exit (0);
  752. + #endif /* !AMIGA */
  753.         }
  754.       }
  755.     return 0;            /* Fool -Wall . . . */
  756. ***************
  757. *** 604,609 ****
  758. --- 765,772 ----
  759.     diffargv[diffargs++] = a;
  760.   }
  761.   
  762. + #ifndef AMIGA
  763.   static void
  764.   execdiff (differences_only, option, file1, file2)
  765.        int differences_only;
  766. ***************
  767. *** 623,631 ****
  768. --- 786,870 ----
  769.     _exit (2);
  770.   }
  771.   
  772. + #else /* AMIGA */
  773. + static void
  774. + execdiff (differences_only, option, file1, file2, asynch, handle)
  775. +      int differences_only;
  776. +      char *option, *file1, *file2;
  777. +      long asynch;
  778. +      BPTR handle;
  779. + {
  780. +   struct TagItem STags[5];
  781. +   if (differences_only)
  782. +     diffarg ("--suppress-common-lines");
  783. +   diffarg (option);
  784. +   diffarg ("--");
  785. +   diffarg (file1);
  786. +   diffarg (file2);
  787. +   diffarg (0);
  788. +   construct_command_line (diffbin, diffargv, command_line);
  789. +   if (asynch)
  790. +     {
  791. +       STags[0].ti_Tag = SYS_Input;
  792. +       STags[0].ti_Data = NULL;
  793. +       STags[1].ti_Tag = SYS_Output;
  794. +       STags[1].ti_Data = handle;
  795. +       STags[2].ti_Tag = SYS_Asynch;
  796. +       STags[2].ti_Data = TRUE;
  797. +       STags[3].ti_Tag = SYS_UserShell;
  798. +       STags[3].ti_Data = TRUE;
  799. +       STags[4].ti_Tag = TAG_DONE;
  800. +       if (System (command_line, STags) != 0)
  801. +         perror_fatal ("diff not found");
  802. +     }
  803. +   else
  804. +     {
  805. +       STags[0].ti_Tag = SYS_Asynch;
  806. +       STags[0].ti_Data = FALSE;
  807. +       STags[1].ti_Tag = SYS_UserShell;
  808. +       STags[1].ti_Data = TRUE;
  809. +       STags[2].ti_Tag = TAG_DONE;
  810. +       if (System (command_line, STags) != 0)
  811. +         perror_fatal ("diff not found");
  812. +       exit (0);
  813. +     }
  814. + }
  815. + static void
  816. + construct_command_line (binname, argvec, com_line)
  817. +      char *binname, **argvec, *com_line;
  818. + {
  819. +   int i;
  820. +   strcpy (com_line, binname);
  821. +   for (i = 1; argvec[i]; i++)
  822. +     {
  823. +       /* Enclose arguments in quotes */
  824. +       strcat (com_line, " \"");
  825. +       strcat (com_line, argvec[i]);
  826. +       strcat (com_line, "\"");
  827. +     }
  828. + }
  829. + static void
  830. + construct_pipe_name (pipe_name)
  831. +      char *pipe_name;
  832. + {
  833. +   static long invocations = 0;
  834. +   struct Task *Task;
  835. +   Task = FindTask (NULL);
  836. +   sprintf (pipe_name, "PIPE:%08lX_%ld", Task, invocations);
  837. + }
  838. + #endif /* !AMIGA */
  839.   
  840.   
  841.   
  842. + #ifndef AMIGA
  843.   /* Signal handling */
  844.   
  845.   static int volatile ignore_signals;
  846. ***************
  847. *** 670,675 ****
  848. --- 909,915 ----
  849.       if (signal (*p, SIG_IGN) != SIG_IGN  &&  signal (*p, catchsig) != SIG_IGN)
  850.         fatal ("signal error");
  851.   }
  852. + #endif /* !AMIGA */
  853.   
  854.   
  855.   
  856. ***************
  857. *** 796,802 ****
  858. --- 1036,1046 ----
  859.         suppress_common_flag = 0;
  860.         break;
  861.       case 'q':
  862. + #ifdef AMIGA
  863. +           user_quit = 1;
  864. + #endif
  865.         return 0;
  866. + #ifndef AMIGA
  867.       case 'e':
  868.         if (! tmpname && ! (tmpname = private_tempnam (0, "sdiff", 1, 0)))
  869.           perror_fatal ("temporary file name");
  870. ***************
  871. *** 865,870 ****
  872. --- 1109,1168 ----
  873.           }
  874.           return 1;
  875.         }
  876. + #else /* AMIGA */
  877. +     case 'e':
  878. +           if (! tmpname && ! (tmpname = tmpnam (NULL)))
  879. +         perror_fatal ("temporary file name");
  880. +       tmpmade = 1;
  881. +       {
  882. +         FILE *tmp;
  883. +             tmp = ck_fopen (tmpname, "w");
  884. +         if (cmd1 == 'l' || cmd1 == 'b')
  885. +           lf_copy (left, lenl, tmp);
  886. +         else
  887. +           lf_skip (left, lenl);
  888. +         if (cmd1 == 'r' || cmd1 == 'b')
  889. +           lf_copy (right, lenr, tmp);
  890. +         else
  891. +           lf_skip (right, lenr);
  892. +         ck_fclose (tmp);
  893. +             {
  894. +               struct TagItem STags[3];
  895. +               sprintf (command_line, "%s \"%s\"", edbin, tmpname);
  896. +               STags[0].ti_Tag = SYS_Asynch;
  897. +               STags[0].ti_Data = FALSE;
  898. +               STags[1].ti_Tag = SYS_UserShell;
  899. +               STags[1].ti_Data = TRUE;
  900. +               STags[2].ti_Tag = TAG_DONE;
  901. +               if (System (command_line, STags) != 0)
  902. +                 perror_fatal ("Subsidiary editor failed");
  903. +         }
  904. +         {
  905. +           static char *buf;
  906. +           size_t size;
  907. +               tmp = ck_fopen (tmpname, "r");
  908. +               buf = xmalloc (SDIFF_BUFSIZE * sizeof (char));
  909. +           while ((size = ck_fread (buf, SDIFF_BUFSIZE, tmp)) != 0)
  910. +         ck_fwrite (buf, size, outfile);
  911. +               free (buf);
  912. +           ck_fclose (tmp);
  913. +         }
  914. +         return 1;
  915. +       }
  916. + #endif /* !AMIGA */
  917.       default:
  918.         give_help ();
  919.         break;
  920. ***************
  921. *** 955,960 ****
  922. --- 1253,1260 ----
  923.     return stat (file, &buf) == 0;
  924.   }
  925.   
  926. + #ifndef AMIGA
  927.   /* These are the characters used in temporary filenames.  */
  928.   static const char letters[] =
  929.     "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789";
  930. ***************
  931. *** 1061,1063 ****
  932. --- 1361,1365 ----
  933.       *lenptr = len;
  934.     return buf;
  935.   }
  936. + #endif /* AMIGA */
  937. diff -cr ram:diff-2.1/system.h dh1:diff-2.1/system.h
  938. *** ram:diff-2.1/system.h    Thu Nov 12 17:02:18 1992
  939. --- dh1:diff-2.1/system.h    Wed Feb 03 20:18:54 1993
  940. ***************
  941. *** 100,110 ****
  942. --- 100,112 ----
  943.   
  944.   #if HAVE_STRING_H || STDC_HEADERS
  945.   #include <string.h>
  946. + #ifndef AMIGA
  947.   #define index    strchr
  948.   #define rindex    strrchr
  949.   #define bcopy(s,d,n)    memcpy (d,s,n)
  950.   #define bcmp(s1,s2,n)    memcmp (s1,s2,n)
  951.   #define bzero(s,n)    memset (s,0,n)
  952. + #endif /* !AMIGA */
  953.   #else
  954.   #include <strings.h>
  955.   #endif
  956. diff -cr ram:diff-2.1/util.c dh1:diff-2.1/util.c
  957. *** ram:diff-2.1/util.c    Thu Nov 12 17:02:18 1992
  958. --- dh1:diff-2.1/util.c    Thu Feb 04 11:53:19 1993
  959. ***************
  960. *** 19,24 ****
  961. --- 19,35 ----
  962.   
  963.   #include "diff.h"
  964.   
  965. + #ifdef AMIGA
  966. + #include <signal.h>
  967. + #include <exec/types.h>
  968. + #include <dos/dostags.h>
  969. + #include <proto/dos.h>
  970. + #include <proto/exec.h>
  971. + extern struct DosLibrary *DOSBase;
  972. + static char tmpfilename[L_tmpnam];
  973. + #endif /* AMIGA */
  974.   /* Use when a system call returns non-zero status.
  975.      TEXT should normally be the file name.  */
  976.   
  977. ***************
  978. *** 154,159 ****
  979. --- 165,171 ----
  980.     strcat (name, current_name1);
  981.   
  982.     if (paginate_flag)
  983. + #ifndef AMIGA
  984.       {
  985.         int pipes[2];
  986.         int desc;
  987. ***************
  988. *** 187,192 ****
  989. --- 199,224 ----
  990.         outfile = fdopen (pipes[1], "w");
  991.       } 
  992.       }
  993. + #else /* AMIGA */
  994. +     {
  995. +       if (DOSBase->dl_lib.lib_Version < 37)
  996. +     {
  997. +       fputs ("Need Amiga OS 2.0 (V.37) to paginate. ", stderr);
  998. +       fputs ("Using stdout instead.\n", stderr);
  999. +       outfile = stdout;
  1000. +     }
  1001. +       else
  1002. +     {
  1003. +       /* Output the differences to a file and process the file with
  1004. +        * pr later on. This is a really bad hack (a kluge??? :-) ),
  1005. +        * but I couldn't find something better... */
  1006. +       tmpnam (tmpfilename);
  1007. +       outfile = fopen (tmpfilename, "w");
  1008. +       if (outfile == NULL)
  1009. +         pfatal_with_name ("pipe");
  1010. +     }
  1011. +     }
  1012. + #endif
  1013.     else
  1014.       {
  1015.   
  1016. ***************
  1017. *** 225,234 ****
  1018. --- 257,308 ----
  1019.   finish_output ()
  1020.   {
  1021.     if (outfile != 0 && outfile != stdout)
  1022. + #ifndef AMIGA
  1023.       {
  1024.         fclose (outfile);
  1025.         wait (0);
  1026.       }
  1027. + #else /* AMIGA */
  1028. +     {
  1029. +       char *command_line;
  1030. +       struct TagItem STags[5];
  1031. +       BPTR StdInPr;
  1032. +       /* Close the temporary file and run pr with this file as input */
  1033. +       fclose (outfile);
  1034. +       command_line = (char *) xmalloc (strlen (current_name0)
  1035. +                        + strlen (current_name1)
  1036. +                        + strlen (switch_string) + 30);
  1037. +       strcpy (command_line, "pr -f -h \"");
  1038. +       strcat (command_line, "diff");
  1039. +       strcat (command_line, switch_string);
  1040. +       strcat (command_line, " ");
  1041. +       strcat (command_line, current_name0);
  1042. +       strcat (command_line, " ");
  1043. +       strcat (command_line, current_name1);
  1044. +       strcat (command_line, "\"");
  1045. +       StdInPr = Open (tmpfilename, MODE_OLDFILE);
  1046. +       if (StdInPr == NULL)
  1047. +     pfatal_with_name ("pipe");
  1048. +       STags[0].ti_Tag = SYS_Input;
  1049. +       STags[0].ti_Data = StdInPr;
  1050. +       STags[1].ti_Tag = SYS_Output;
  1051. +       STags[1].ti_Data = Output ();
  1052. +       STags[2].ti_Tag = SYS_Asynch;
  1053. +       STags[2].ti_Data = FALSE;
  1054. +       STags[3].ti_Tag = SYS_UserShell;
  1055. +       STags[3].ti_Data = TRUE;
  1056. +       STags[4].ti_Tag = TAG_DONE;
  1057. +       if (System (command_line, STags) != 0)
  1058. +     {
  1059. +       Close (StdInPr);
  1060. +       DeleteFile (tmpfilename);
  1061. +       pfatal_with_name ("pr");
  1062. +     }
  1063. +       Close (StdInPr);
  1064. +       DeleteFile (tmpfilename);
  1065. +     }
  1066. + #endif /* !AMIGA */
  1067.   
  1068.     outfile = 0;
  1069.   }
  1070.